cmake_minimum_required(VERSION 3.15)
project(corexi-common-pc VERSION 1.0.0 LANGUAGES CXX)


include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

include(cmake/option.cmake)

# 统一所有目标输出目录（可根据需要改为 ${CMAKE_SOURCE_DIR}/out）
set(CMAKE_DEBUG_POSTFIX d)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# 兼容多配置生成器（例如 MSVC 的 Debug/Release）
if (CMAKE_CONFIGURATION_TYPES)
    foreach (OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
        string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIGU)
        set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIGU} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
        set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIGU} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
        set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIGU} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
    endforeach ()
endif ()

list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/windows")
list(APPEND "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/windows")
add_subdirectory(common)
add_subdirectory(controls)
add_subdirectory(api)
add_subdirectory(ftc)
if (BUILD_TEST)
    enable_testing()
    add_subdirectory(test)
endif ()

if (BUILD_SAMPLE)
    add_subdirectory(sample)
endif ()

install(EXPORT CxiCommonPcTargets
        FILE CxiCommonPcTargets.cmake
        NAMESPACE CxiCommonPc::
        DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CxiCommonPc
)
# 版本文件
write_basic_package_version_file(
        ${CMAKE_CURRENT_BINARY_DIR}/CxiCommonPcConfigVersion.cmake
        VERSION ${PROJECT_VERSION}
        COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
        ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CxiCommonPcConfig.cmake.in
        ${CMAKE_CURRENT_BINARY_DIR}/CxiCommonPcConfig.cmake
        INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CxiCommonPc
)

install(FILES
        ${CMAKE_CURRENT_BINARY_DIR}/CxiCommonPcConfig.cmake
        ${CMAKE_CURRENT_BINARY_DIR}/CxiCommonPcConfigVersion.cmake
        DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CxiCommonPc
)

# 安装common依赖第三方库
get_filename_component(INSTALL_PREFIX_PARENT ${CMAKE_INSTALL_PREFIX} DIRECTORY)
install(DIRECTORY 3rdparty/windows/
        DESTINATION ${INSTALL_PREFIX_PARENT}
)

install_qt_libs(${CMAKE_RUNTIME_OUTPUT_DIRECTORY} QT_LIBS
        Core
        Gui
        Widgets
        Test
        Designer
        Network
)

#create_log_config("cxi-common-log"  ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})